<template>
    <div class="mytooltip-box">
        <div class="filter">
            <span>{{ leftSeek }}</span>
            <div class="icon-box">
                <i class="iconfont iconxiala2"></i>
                <!-- <div class="triangle" v-show="show"></div> -->
                <div class="box">
                    <div class="mytooltip" v-if="list && list.length">
                        <div :class="{ active: i === statusIndex }" v-for="(v, i) in list" :key="i" @click="command1(v, i)">
                            {{ v[range_key] }}
                            <span v-if="v.count !== undefined && v.count !== null && v.count + ''" style="font-size:12rem;">({{ v.count }})</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: "qg-session-select",
    props: {
        list: {
            type: Array,
            default: () => [],
        },
        range_key: {
            type: String,
            default: "name",
        },
        range_value: {
            type: String,
            default: "id",
        },
        immediate: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            active: "active",
            statusIndex: 0,
            leftSeek: "全部",
        };
    },
    watch: {
        list: {
            handler(n) {
                if (n && n.length) {
                    this.leftSeek = n[0][this.range_key];
                    if (this.immediate) {
                        this.$emit("change", n[0][this.range_value]);
                    }
                }
            },
            deep: true,
            immediate: true,
        },
    },
    methods: {
        command1(e, i) {
            this.leftSeek = e[this.range_key];
            this.statusIndex = i;
            this.$emit("change", e[this.range_value]);
        },
    },
};
</script>

<style lang="less" scoped>
.mytooltip-box {
    &:hover .box {
        display: block;
    }
}
.filter {
    display: flex;
    align-items: center;
    .iconxiala2 {
        font-size: 12rem;
    }
    span {
        font-size: 18rem;
    }
}
.icon-box {
    position: relative;
    width: 31rem;
    text-align: right;
    .triangle {
        &::before {
            content: "";
            position: absolute;
            left: 19rem;
            top: 20rem;
            width: 0rem; /*设置宽高为0，所以div的内容为空，从才能形成三角形尖角*/
            height: 0rem;
            border-right: 6rem solid transparent;
            border-bottom: 6rem solid rgb(12, 10, 10); /*transparent 表示透明*/
            border-left: 6rem solid transparent;
            margin-left: 0rem;
            margin-top: 10rem;
        }
    }
}
.box {
    display: none;
    padding-top: 40rem;
    position: absolute;
    left: -34rem;
    top: -5rem;
    z-index: 100;
}
.mytooltip {
    color: #000 !important;
    padding: 10rem;
    border-radius: 3rem;
    background-color: #000;
    max-height: 300rem;
    overflow: auto;
    &::after {
        content: "";
        position: absolute;
        left: 53rem;
        top: 24rem;
        width: 0rem; /*设置宽高为0，所以div的内容为空，从才能形成三角形尖角*/
        height: 0rem;
        border-right: 6rem solid transparent;
        border-bottom: 6rem solid rgb(12, 10, 10); /*transparent 表示透明*/
        border-left: 6rem solid transparent;
        margin-left: 0rem;
        margin-top: 10rem;
    }
    & > div {
        width: 100rem;
        padding: 12rem 0;
        color: #fff;
        font-size: 12rem;
        text-align: center;
        cursor: pointer;
        line-height: 1;
        border-radius: 20rem;
        background-color: #2e2e2e;
        margin-bottom: 10rem;
        &.active {
            background-color: #7659ff;
        }
    }
    & > div:hover {
        background-color: #7659ff;
    }
}
</style>
